<?php
class lienhe_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	} 

	function count_list()
	{
		$this->db->where('bl_active !=',-1);
		$query = $this->db->get('lienhe');
		return $query->num_rows();
	}

	function get_list($num,$offset)
	{
		$this->db->where('bl_active !=',-1);
		$query = $this->db->get('lienhe');
		return $query->result();
	}

	function getlienhe($id=0, $num=15, $start=0)
	{ 
		if(!empty($id)) $this->db->where('id',$id);
		$query = $this->db->get('lienhe', $num, $start);
		return $query->row();
	}

	function set_view($id)
	{
		$data = array(
			'bl_active' => 0
		);
		$this->db->where('id',$id);
		$this->db->update('lienhe',$data) ;
	}


	function save()
	{
		$id = (int)$this->uri->segment(3);
		$subject_vn = $this->input->post('subject_vn');
		$address_vn = $this->input->post('address_vn');
		$ks_image  = $this->input->post('ks_image');
		$subcontent_vn = $this->input->post('subcontent_vn');
		$content_vn  = $this->input->post('content_vn');
		$bl_active  = $this->input->post('bl_active');
		
		$data = array(
			'subject_vn' => $subject_vn,
			'alias_vn' => strtolower(stringchange($subject_vn)),
			'address_vn' => $address_vn,
			'subcontent_vn' => $subcontent_vn,
			'content_vn' => $content_vn,
			'ks_image' => $ks_image,
			'bl_active' 	=> $bl_active
		);
		if($id != 0)
		{
		  $this->db->where('id',$id);
		  if($this->db->update('lienhe',$data)){
			  return true;
		  }else{
			  return false;
		  }
		}else{
		
		  if($this->db->insert('lienhe',$data)){
			  return true;
		  }else{
			  return false;
		  }
		}          
	}

	function delete($id)
	{
		$data = array(
			'bl_active' 	=> -1
		);
		$this->db->where('id',$id);
		$this->db->update('lienhe',$data) ;
	}
}
?>